package com.kld.yqyj.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.kld.common.annotation.RepeatSubmit;
import com.kld.common.annotation.Log;
import com.kld.common.core.controller.BaseController;
import com.kld.common.core.domain.PageQuery;
import com.kld.common.core.domain.R;
import com.kld.common.core.validate.AddGroup;
import com.kld.common.core.validate.EditGroup;
import com.kld.common.core.validate.QueryGroup;
import com.kld.common.enums.BusinessType;
import com.kld.common.utils.poi.ExcelUtil;
import com.kld.yqyj.domain.vo.TOwDVo;
import com.kld.yqyj.domain.bo.TOwDBo;
import com.kld.yqyj.service.ITOwDService;
import com.kld.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 采油井生产日报Controller
 *
 * @author bw
 * @date 2024-05-15
 */
@Validated
@Api(value = "采油井生产日报控制器", tags = {"采油井生产日报管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/yqyj/owD")
public class TOwDController extends BaseController {

    private final ITOwDService iTOwDService;

    /**
     * 查询采油井生产日报列表
     */
    @ApiOperation("查询采油井生产日报列表")
    @SaCheckPermission("yqyj:owD:list")
    @GetMapping("/list")
    public TableDataInfo<TOwDVo> list(@Validated(QueryGroup.class) TOwDBo bo, PageQuery pageQuery) {
        return iTOwDService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出采油井生产日报列表
     */
    @ApiOperation("导出采油井生产日报列表")
    @SaCheckPermission("yqyj:owD:export")
    @Log(title = "采油井生产日报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated TOwDBo bo, HttpServletResponse response) {
        List<TOwDVo> list = iTOwDService.queryList(bo);
        ExcelUtil.exportExcel(list, "采油井生产日报", TOwDVo.class, response);
    }

    /**
     * 获取采油井生产日报详细信息
     */
    @ApiOperation("获取采油井生产日报详细信息")
    @SaCheckPermission("yqyj:owD:query")
    @GetMapping("/{wellId}")
    public R<TOwDVo> getInfo(@ApiParam("主键")
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("wellId") String wellId) {
        return R.ok(iTOwDService.queryById(wellId));
    }

    /**
     * 新增采油井生产日报
     */
    @ApiOperation("新增采油井生产日报")
    @SaCheckPermission("yqyj:owD:add")
    @Log(title = "采油井生产日报", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TOwDBo bo) {
        return toAjax(iTOwDService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改采油井生产日报
     */
    @ApiOperation("修改采油井生产日报")
    @SaCheckPermission("yqyj:owD:edit")
    @Log(title = "采油井生产日报", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TOwDBo bo) {
        return toAjax(iTOwDService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除采油井生产日报
     */
    @ApiOperation("删除采油井生产日报")
    @SaCheckPermission("yqyj:owD:remove")
    @Log(title = "采油井生产日报", businessType = BusinessType.DELETE)
    @DeleteMapping("/{wellIds}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable String[] wellIds) {
        return toAjax(iTOwDService.deleteWithValidByIds(Arrays.asList(wellIds), true) ? 1 : 0);
    }
}
